package msu.ml.tools;

import msu.ml.util.*;
import org.w3c.dom.*;

public class BMToCSV
{
   public static void main(String [] args)
   {
      try
      {
         Document doc = XmlUtility.parseXmlFile(args[0]);     
         NodeList list = XmlUtility.xPathQuery(doc, 
            "//sweep[not(child::error)]");
         for(int i = 0; i < list.getLength(); i++)
         {
            Element sweep = ((Element)list.item(i));
            System.out.print(sweep.getAttribute("id") + ", ");
            System.out.print(sweep.getAttribute("file") + ", ");
            System.out.print(sweep.getAttribute("station") + ", ");
            System.out.print(sweep.getAttribute("date") + ", ");
            System.out.print(sweep.getAttribute("time") + ", ");

            Node rTime = XmlUtility.getSingleNode(sweep, "retrieval_time");
            System.out.print(rTime.getTextContent() + ", ");

            Node cTime = XmlUtility.getSingleNode(sweep, "classification_time");
            System.out.print(cTime.getTextContent() + ", ");

            Node tTime = XmlUtility.getSingleNode(sweep, "total_time");
            System.out.print(tTime.getTextContent() + ", ");

            Node bio = XmlUtility.getSingleNode(sweep, "biological");
            System.out.print(bio.getTextContent() + ", ");

            Node nbio = XmlUtility.getSingleNode(sweep, "nonbiological");
            System.out.print(nbio.getTextContent() + ", ");

            Node tag = XmlUtility.getSingleNode(sweep, "classification");
            System.out.print(tag.getTextContent());
            System.out.println();
         }
      }
      catch(Exception e)
      {
         System.out.println(e.getMessage());
      }
   }
}
